package com.imooc.miaosha.activemq;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

import com.imooc.miaosha.redis.RedisService;

import javax.jms.Destination;

@Service
public class MQSender {

	private static Logger log = LoggerFactory.getLogger(MQSender.class);

	@Autowired
	private JmsMessagingTemplate jmsMessagingTemplate;

	public void sendMiaoshaMessage(MiaoshaMessage mm) {
		String msg = RedisService.beanToString(mm);
		log.info("send message:"+msg);
		Destination destination = new ActiveMQQueue(MQConfig.MIAOSHA_QUEUE);
		jmsMessagingTemplate.convertAndSend(destination, msg);
	}
	
	public void send(Object message) {
		String msg = RedisService.beanToString(message);
		log.info("send message:"+msg);
		Destination destination = new ActiveMQQueue(MQConfig.QUEUE);
		jmsMessagingTemplate.convertAndSend(destination, msg);

	}

	public void sendTopic(Object message) {
		String msg = RedisService.beanToString(message);
		log.info("send topic message:"+msg);
		Destination topic = new ActiveMQTopic(MQConfig.TOPIC_QUEUE1);

		jmsMessagingTemplate.convertAndSend(topic,"topic,world1!" );

	}



	
	
}
